<%@ include file="/include/taglibs.jsp"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<script type="text/javascript" src="${ctx}/script/jquery/jquery.form.js"></script>
<div id="showGoodDiv" style="border:solid 2px #1f6ca3;">
	<div class="popup">
	<div class='frameTitle'>
		<div class='titleLeft'>
			<div class='titleRight'>
				<div class='titleCenter'>
					<div class='titleContent'>
						<div class='dialogTitleText'>商品信息</div>
						<div class='titleBtn'><a href='#' onclick="$.closePopupLayer('showGoodDiv')">关闭</a></div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="popup-body">


	 <!--页面中部内容-开始-->
	 <div class="common_wraper">
	 	<div class="winTopOuter">
	 		<div class="winTopInner"></div>
	 	</div>
	 	<div class="winContent" id="contextId">
	 	<form id="updatecommodityForm" action="${ctx}/buycar/buycarAction!updateCommodity.action" method="post">
	 		<input type="hidden" name="commodity.id" value="${commodity.id}"/>
	 		<div class="winTitle">
	 			请填写用户注册信息
	 		</div>
	 		<div class='statusImg'></div>
	 		<div class='orderTable' >
	 			<table>
	 				<tbody>
	 					<tr>
	 						<td rowspan="10" width=210px; valign='top' align='center'>
 							<div>照片信息</div>
 							<div style='width:200px;height:200px;' class='commodityImg' id='commodityImg' ></div>
 							<input id="commodityImgUrl" name="commodity.imgurl" type="hidden"  value="${commodity.imgurl}"></input>
	 						</td>
	 						<td class='orderTdTitle'>商品页网址：</td>
	 						<td>
	 						<input type='text' class='commonInput url' id='url' name='commodity.url' value='${commodity.url}' onchange="parseUrl()"></input><div class="flushUrl" title="点击后系统自动刷新商品信息" ><a href="javascript:parseUrl()"></a></div><div class="checkError" id="urlTip"><div class="msg">aaaaaaaaaaaa</div></div>
	 						<div style="clear:both;">目前支持：淘宝，当当。。。。。</div>
							</td>
	 						<td></td>
	 					</tr>
	 					<tr>
	 						<td class='orderTdTitle' >商品名称：</td>
	 						<td><input type='text' class='commonInput' id='commodityname' name='commodity.name'  value="${commodity.name}"></input><div class="checkError" id="commoditynameTip"><div class="msg">aaaaaaaaaaaa</div></div> </td>
	 						<td> </td>
	 					</tr>
	 					<tr>
	 						<td class='orderTdTitle' >来源买家：</td>
	 						<td><input type='text' class='commonInput' id='shopName' name='commodity.shopname' value="${commodity.shopname}"></input><div class="checkError" id="shopNameTip"><div class="msg">aaaaaaaaaaaa</div></div> </td>
	 						<td> </td>
	 					</tr>
	 					<tr>
	 						<td class='orderTdTitle' >商品价格：</td>
	 						<td><input type='text' class='commonInput' id='price' name='commodity.price' value="${commodity.price}"></input> <div class="checkError" id="priceTip"><div class="msg">aaaaaaaaaaaa</div></div></td>
	 						<td> </td>
	 					</tr>
	 					<tr>
	 						<td class='orderTdTitle' >国内运费：</td>
	 						<td><input type='text' class='commonInput' id='freight' name='commodity.freight' value='${commodity.freight}' ></input><div class="checkError" id="freightTip"><div class="msg">aaaaaaaaaaaa</div></div> </td>
	 						<td> </td>
	 					</tr>
	 					<tr>
	 						<td class='orderTdTitle' >商品数量：</td>
	 						<td><input  type='text' class='commonInput' onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
	 						 id='buycount' name='commodity.buycount' value="1" /><label onclick="addCount(1)"  class='addCount' id='add' name='add' ></label><label onclick="addCount(-1)"  class='minusCount' id='minus' name='minus'></label> 
	 						 <div class="checkError" id="buycountTip"><div class="msg">aaaaaaaaaaaa</div></div>
	 						 </td>
	 					</tr>
	 					<tr>
	 						<td class='orderTdTitle' >备注信息：</td>
	 						<td><textarea id='remark' cols="50" rows="6" name='commodity.remark' >${commodity.remark}</textarea><div class="checkError" id="remarkTip"><div class="msg">aaaaaaaaaaaa</div></div> </td>
	 						<td> </td>
	 					</tr>
	 					<tr>
	 						<td class='orderTdTitle' ></td>
	 						<td><div class='submitBtn'><a href="#" onclick="submitUpdateGoodInfo()"  id='submitText'  name='submitText'  class='submitTextCss'>提交代购</a> <a href="#"  onclick="clearForm('commodityForm')"  id='clearText'  name='clearText'  class='clearTextCss'>清空数据</a></div></td>
	 						<td> </td>
	 					</tr>
	 				</tbody>
	 			</table>	 
	 		
	 		</div> 
	 		 </form>
	 	</div>
	 	<div class="winBottomOuter">
	 		<div class="winBottomInner"></div>
	 	</div>
	 </div>

<script type="text/javascript">
function clearForm(id){
	$("#"+id+"input[type='text']").val("");
	$("#"+id+"input[type='password']").val("");
	$("#"+id+"input[type='checkbox']").attr("checked","");
	$("#"+id+"input[type='radio']").attr("checked","");
	$("#"+id+"option").attr("selected","");
}
function showCheck(id,msg){
	var id="#"+id+"Tip";
	$(id).show();
	$(id).find("div[class='msg']").html(msg);
}
function hideCheck(id){
	var id="#"+id+"Tip";
	$(id).hide();
	$(id).find("div[class='msg']").html("");
}
function submitUpdateGoodInfo(){
	//判断数据是否为空
	if($("#url").val()==null || $("#url").val()==''){
//		JBF.createFocusTip($("#url"),"商品地址不能为空");
		showCheck("url","商品地址不能为空");
		return ;
	}else{
		hideCheck("url");
	}
	if($("#commodityname").val()==null || $("#commodityname").val()==''){
		showCheck("commodityname","商品名称不能为空");
		return ;
	}else{
		hideCheck("commodityname");
	}
	if($("#shopName").val()==null || $("#shopName").val()==''){
		showCheck("shopName","卖家名称不能为空");
		return ;
	}else{
		hideCheck("shopName");
	}
	if($("#price").val()==null || $("#price").val()==''){
		showCheck("price","商品价格不能为空");
		return ;
	}else{
		hideCheck("price");
	}
	if($("#freight").val()==null || $("#freight").val()==''){
		showCheck("freight","国内运费不能为空");
		return ;
	}else{
		hideCheck("freight");
	}
	var cNum=$("#buycount").val();
	if(cNum>=1){
		hideCheck("buycount");
	  $('#updatecommodityForm').submit();
       });
	}else{
		showCheck("buycount","国内运费不能为空");
	}
}
function addCount(num){
	var cNum=$("#buycount").val();
	if(cNum!=null && cNum!=''){
		if(num<0){
			if(cNum>1){
				$("#buycount").val(parseInt(cNum)-1);
			}
		}else{
			$("#buycount").val(parseInt(cNum)+1);
		}
	}
}
function parseUrl(){
	  var url=$("#url").val();
	if(url!=null && url!=''&& url.length>7 && url.substr(0,5)=='http:'){
		hideCheck("url");
		  var ajaxurl="${ctx}/buycar/buycarAction!ajaxParseUrl.action";
		   $.ajax({
				type: "post",
				url: url,
				dataType: "json",
				data:{"parseUrl":url,"timeTemp":new Date().getTime()},   
				success: function(data){
					 if(data!=null && data!=''){
						 //设值
						 $("#commodityImg").val(data.imgurl);
						 $("#url").val(data.url);
						 $("#commodityname").val(data.name);
						 $("#shopName").val(data.domainname);
						 $("#price").val(data.price);
						 $("#freight").val(data.freight);
						 $("#buycount").val(data.buyCount);
						 $("#remark").html("");
					 }else{
						 alert("没有抓取到商品,请手动填写");
					 }
					}
				});
	}else{
		showCheck("url","输入网址信息无效");
	}
}

(function showTip(){
	var formDatas=[["commodityImg","商品图片"],["url","商品地址"],["commodityname","商品名称"],["shopName","卖家名称"],["price","商品价格"],["freight","国内运费"],["buycount","购买数量"],["remark","备&nbsp;注"]];
	for(var i=0;i<formDatas.length;i++){
		
		(function(index){
			var data=formDatas[index];
			var id=data[0];
			var showTip=data[1];
			var obj=JBF.el(id);
			JBF.addEvent(obj,"mouseover",function(){
				JBF.createFocusTip(obj,showTip);
			});
			JBF.addEvent(obj,"mouseout",function(){
				var tipDiv=JBF.el("focusTipInput");
				if(tipDiv){
					tipDiv.style.display="none";
				}
			});
			JBF.addEvent(obj,"focus",function(){
				obj.className+=" inputFocus";
			});
			JBF.addEvent(obj,"blur",function(){
				obj.className=obj.className.replace(" inputFocus","");
			})
		})(i);

	}
})();
</script>
	</div>
	</div>
</div>